<?php
namespace Home\Controller;
use Think\Controller;
class LoginController extends Controller {
	//初始化方法
	protected function _initialize(){
		
	}
	
	//登录页面
    public function index(){
		
		//用户页面
		$this->display();
		
    }
	
	//登录验证
	public function check(){
		$code=I('post.fcode');
		$username=I('post.username');
		$password=I('post.password');
		
		$user=M('User');
		$where=array('username'=>$username,'password'=>md5($password));
		
		if(!$this->check_verify($code)){
			$this->error("验证码错误！");
			exit;
		}
		
		$row=$user->where($where)->find();
		if($row){
			$_SESSION['username']=$username;
			$_SESSION['islogin']=TRUE;
			$this->success('登录成功！',U('Index/index'));
		}else{
			$this->error('用户名或密码错误！');
		}
		//echo $user->getLastSql();
	}
	
	//退出登录
	public function logout(){
		
	}
	
	//验证码
	public function verify(){
		$Verify = new \Think\Verify();
		$Verify->length = 4;
		$Verify->codeSet = '0123456789';
		$Verify->entry();
	}
	
	private function check_verify($code, $id = ''){
		$verify = new \Think\Verify();
		return $verify->check($code, $id);
	}
	
}